import '../../global/user/logic.dart';
import '../util.dart';
import 'http_man.dart';
import 'urlpath.dart';

class Api {
  //登录
  static Future<NetBaseReponse> login(Map<String, dynamic> param) {
    return HttpMan.instance.post(UrlPath.login, args: param);
  }

  //注册
  static Future<NetBaseReponse> register({
    required String code,
    required String password,
    required String telephone,
  }) {
    return HttpMan.instance.post(UrlPath.register, args: {
      'code': code,
      'orgName': "ios-apply",
      'password': password,
      'telephone': telephone,
    });
  }

  //发送验证码
  static Future<NetBaseReponse> sendCode(Map<String, dynamic> param) {
    return HttpMan.instance.post(UrlPath.sendCode, args: param);
  }

  //修改密码
  static Future<NetBaseReponse> updatePassword({
    required String old,
    required String newPwd,
    required String repeatPwd,
  }) {
    return HttpMan.instance.post(UrlPath.updatePassword, args: {
      "oldPwd": old,
      "newPwd": newPwd,
      "repeatPwd": repeatPwd,
      "type": "1",
      "tenantId": UserController.instance.state.user?.tenantId,
    });
  }

  //注册
  static Future<NetBaseReponse> validate(String pwd) {
    return HttpMan.instance.post(UrlPath.cancellationOfAccount, args: {
      'loginName': UserController.instance.state.user?.loginName ?? '',
      'loginPassword': pwd,
    });
  }
}

extension HomeApi on Api {
  // static Future<NetBaseReponse<PageModel<WeekRecordModel>>>
  //     pageSelfRecordSuggest<T>({
  //   required int pageIndex,
  //   bool isLoading = true,
  // }) {
  //   var user = UserController().state.user;
  //   return HttpMan.instance.get(
  //     UrlPath.pageSelfRecordSuggest,
  //     args: {
  //       'current': pageIndex,
  //       "size": 5,
  //       "optionUserId": user?.userId,
  //       'tenantId': user?.tenantId,
  //     },
  //     fromJsonT: (json) =>
  //         PageModel.fromJson(json, (item) => WeekRecordModel.fromJson(item)),
  //     loadding: isLoading,
  //   );
  // }

  // static Future<NetBaseReponse<UserListModel>> getAllUserList() {
  //   return HttpMan.instance.get(
  //     UrlPath.getAllUserList,
  //     fromJsonT: (json) => UserListModel.fromJson(json),
  //   );
  // }
}

class MeApi extends Api {
  static Future<NetBaseReponse> versionUpdate() {
    return HttpMan.instance.get(UrlPath.checkUpdate);
  }
}
